 SWEP.Author = "Sam Douglas";
 SWEP.Contact = "sam.douglas32@gmail.com";
 SWEP.Purpose = "Assists in throwing chairs";
 SWEP.Instructions = "Left click to throw an office chair; right click to throw a wooden chair";
  
 SWEP.Spawnable = true;
 SWEP.AdminSpawnable = true;
  
 SWEP.ViewModel = "models/weapons/v_pistol.mdl";
 SWEP.WorldModel = "models/weapons/w_pistol.mdl";
  
 SWEP.Primary.ClipSize = -1;
 SWEP.Primary.DefaultClip = -1;
 SWEP.Primary.Automatic = false;
 SWEP.Primary.Ammo = "none";
  
 SWEP.Secondary.ClipSize = -1;
 SWEP.Secondary.DefaultClip = -1;
 SWEP.Secondary.Automatic = false;
 SWEP.Secondary.Ammo = "none";
  
 local ShootSound = Sound ("Metal.SawbladeStick");
  
 /* Both Reload() and Think() are not needed by this SWEP so we
  * will provide empty functions for them
  */
 function SWEP:Reload()
 end
  
 function SWEP:Think()
 end
  
 /* Spawn and throw the specified model */
 function SWEP:throw_attack (model_file)
  //Get an eye trace. This basically finds out where the shot hit
  //This SWEP makes very little use of the trace, except to calculate
  //the amount of force to apply to the object to throw it.
  local tr = self.Owner:GetEyeTrace();
  
  //We now make some shooting noises and effects using the sound we
  //loaded up earlier
  self.Weapon:EmitSound (ShootSound);
  self.BaseClass.ShootEffects (self);
  
  //We now exit if this function is not running on the server
  if (!SERVER) then return end;
  
  //The next task is to create a physics entity based on the supplied model.
  local ent = ents.Create ("prop_physics");
  ent:SetModel (model_file);
  
  //Set the initial position of the object. This might need some fine tuning; but it
  //seems to work for the models I have tried
  ent:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16));
  ent:SetAngles (self.Owner:EyeAngles());
  ent:Spawn();
  
  //Now we need to get the physics object for our entity so we can apply a force to it
  local phys = ent:GetPhysicsObject();
 
  //Time to apply the force. My method for doing this was almost entirely empirical
  //and it seems to work fairly intuitively with chairs.
  local shot_length = tr.HitPos:Length();
  phys:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length, 3));
  
  //Now for the all important part of adding the spawned objects to the undo and cleanup data.
  cleanup.Add (self.Owner, "props", ent);
  
  undo.Create ("Thrown chair");
  undo.AddEntity (ent);
  undo.SetPlayer (self.Owner);
  undo.Finish();
 end
  
 /* Throw an office chair on primary attack */
 function SWEP:PrimaryAttack()
  //Call the throw attack function
  self:throw_attack ("models/props/cs_office/Chair_office.mdl");
 end
  
 /* Throw a wooden chair on secondary attack */
 function SWEP:SecondaryAttack()
  //Call the throw attack function
  self:throw_attack ("models/props_c17/FurnitureChair001a.mdl");
 end 